package demo2;

import java.util.Arrays;

public class LeetCode1089 {
    public void duplicateZeros(int[] arr) {
        int n = arr.length;
        int slow = -1, fast = 0;
        while(fast < n) {
            slow++;
            if(arr[slow] != 0) fast++;
            else fast += 2;
        }
        int tmp = n - 1;
        if(fast == n + 1) {
            arr[tmp--] = 0;
            slow--;
        }
        while(tmp >= 0) {
            if(arr[slow] == 0) {
                arr[tmp--] = arr[slow];
                arr[tmp--] = arr[slow--];
            } else {
                arr[tmp--] = arr[slow--];
            }
        }
        System.out.println(Arrays.toString(arr));
    }
}
